<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="vue.js"></script>
    <title>Title</title>
</head>
<body>
<div id="example">
    <p>Original message: "{{ message }}"</p>
    <p>Computed reversed message: "{{ reversedMessage }}"</p>
    <p>full name: "{{ fullName }}"</p>
    <p>
        Ask a yes/no question:
        <input v-model="question">
    </p>
    <p>{{ answer }}</p>
</div>
</body>
</html>
<script>
    var vm = new Vue({
        el: '#example',
        data: {
            message: 'Hello',
            firstName: 'Foo',
            lastName: 'Bar',
            question: '',
            answer: ''
        },
        computed: {
            reversedMessage: function () {
                return this.message.split('').reverse().join('');
            },
            fullName: {
                get: function () {
                    return this.firstName + " " + this.lastName;
                },
                set: function (newValue) {
                    var names = newValue.split(' ');
                    this.firstName = names[0];
                    this.lastName = names[names.length - 1];
                }
            }
        },
        watch: {
            question: function (newQuestion) {
                this.answer = 'waiting...'
                this.getAnswer(newQuestion);
            }
        },
        methods: {
            getAnswer: function (newQuestion) {
                setTimeout(function () {
                    vm.answer = 'i don\'t know \'' + newQuestion + '\'';
                }, 500);
            }
        }
    });
</script>
